@model OA.Model.Dialog
@{
    ViewBag.Title = Model.Title + "_数据选择对话框";
 }
@section head{
  <script type="text/javascript">
      var details
      var options
      var currentCommand;
      var where;
      $.fn.pagination.defaults.displayMsg='{from}-{to}/{total}';
      $(document).ready(function () {
            details=$('#details');
            options = details.datagrid('options');
            options.singleSelect=@((ViewBag.multiSelected==false).ToString().ToLower());
            var firstShow=@((ViewBag.firstShow==true).ToString().ToLower());
            if(firstShow){
               show();
            }
            else{
               query_click();
            }
      });
      function query_click(){
          details.datagrid('loadData',[]);
          details.datagrid('appendRow',{});
          details.datagrid('beginEdit',0);
          details.prev().find('.datagrid-body tr').find('td:eq(1) input')[0].focus();
          options.url=undefined;

          $('#panConfirm').show();
          $('#panShow').hide();

          currentCommand='query';
      }

      function show()
      {
         details.datagrid('loadData',[]);
         if(options.url==undefined) options.url = '@Url.Action("DialogData")?dialogCode=@Model.DialogCode&where=@Html.Raw(ViewBag.where)';
         details.datagrid('load',where);

          $('#panConfirm').hide();
          $('#panShow').show();

          currentCommand='show';
      }

      function confirm_click(){
          if(currentCommand=='query')
          {
             details.datagrid('endEdit',0);
             var rows=details.datagrid('getRows');
             where=rows[0];
             show();
          }
          else{
             var rows=details.datagrid('getSelections');
             if(rows.length>0){
                this.frameElement.OnSelected(rows);
             }
          }
      }

      function cancel_click(){
          this.frameElement.Cancel();
      }

  </script>
}
@section body{
<body style="padding:@ViewBag.Padding">
<div class="easyui-layout" data-options="fit:true">
    <div region="east" data-options="border:false" class="commands"  >
        <div class="easyui-panel"  data-options="fit:true, padding:0" style="overflow:hidden;">
            <div id="panConfirm">
                 <a href="javascript:void(0);" onclick="confirm_click()" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">确定</a>  
                 <a href="javascript:void(0);" onclick="cancel_click()"   class="easyui-linkbutton" data-options="iconCls:'icon-cancel'">取消</a> 
            </div>
            <div id="panShow">
                 <a href="javascript:void(0);" onclick="confirm_click()" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">确定</a>  
                 <a href="javascript:void(0);" onclick="cancel_click()"   class="easyui-linkbutton" data-options="iconCls:'icon-cancel'">取消</a> 
                 <a href="javascript:void(0);" onclick="query_click()"   class="easyui-linkbutton" data-options="iconCls:'icon-search'">查询</a> 
            </div>
        </div>
    </div>
    <div id='content' data-options="region:'center',border:false" >
        <table class="easyui-datagrid" id="details" data-options="fit:true,rownumbers:true,
            pagination:true,border:true">
            <thead>
                 <tr>
                    <th data-options="checkbox:true"></th>
               @foreach (var field in Model.Fields)
               {
                   if (field.IsShow)
                   {
                     <th data-options="field:'@field.FieldKey',sortable:true,width:@field.Width,editor:{type:'validatebox'}">@field.Title</th>
                   }
               }
               </tr>
            </thead>
        </table>
    </div>
</div>
</body>
}